<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>点标记</title>
    <link rel="stylesheet" href="{$protocol}cache.amap.com/lbs/static/main1119.css"/>
    <script src="{$protocol}webapi.amap.com/maps?v=1.4.6&key=您申请的key值"></script>
    <script type="text/javascript" src="{$protocol}cache.amap.com/lbs/static/addToolbar.js"></script>
    <script src="__PUBLIC__/js/jquery.js"></script>
</head>
<body>
<div id="container"></div>
<script>
    window.onload =initMap;
    var common_id = "{$common_id}";
    var map,marker,timeVal;
    function initMap(){
        $.post('/admin/order/getLocal', {common_id: common_id}, function (res) {
            if (res['status']) {
                map = new AMap.Map("container", {
                    resizeEnable: true,
                    center: JSON.parse(res['data']),
                    zoom: 16
                });
                marker = new AMap.Marker({
                    position: JSON.parse(res['data']),
                    offset: new AMap.Pixel(-20, -10),
                    angle : res['angle'],
                    icon: new AMap.Icon({
                        size: new AMap.Size(41, 19),  //图标大小
                        image: res['car_img'],
                        imageOffset: new AMap.Pixel(0, 0),
                        imageSize:new AMap.Size(41, 19)
                    }),
                    title: res['msg']
                });
                marker.setMap(map);
                timeVal = setInterval(updateMarker,5000);
            } else {
                alert(res['msg']);
            }
        });
    }

    function updateMarker() {
        $.post('/admin/order/getLocal', {common_id: common_id}, function (res) {
            if (res['status']) {
                map.remove(marker);
                map.setZoomAndCenter(16, JSON.parse(res['data']));
                marker = new AMap.Marker({
                    position: JSON.parse(res['data']),
                    icon: new AMap.Icon({
                        size: new AMap.Size(41, 19),  //图标大小
                        image: res['car_img'],
                        imageOffset: new AMap.Pixel(0, 0),
                        imageSize:new AMap.Size(41, 19)
                    }),
                    title: res['msg']
                });
                marker.setMap(map);
            } else {
                alert(res['msg']);
                clearInterval(timeVal);
            }
        });
    }
</script>
</body>
</html>